import Vue from 'vue'
import store from '@/store'
Vue.directive('has', {
	inserted: function(el, binding) {
		// setTimeout(()=>{
			if (store.getters.buttomList&&!store.getters.buttomList.includes(binding.value)) {
				el.parentNode.removeChild(el); //调用元素父级删除，有时候父元素未渲染出来可以把bind换成inserted
			}
		// },800)
	}
})
//限制输入框只能输入数字
Vue.directive('onkeypress', {
	bind: function(el, binding) {
		el.onkeypress=function(e){
			const ev = e || event
			let num =String.fromCharCode(ev.keyCode||ev.which)
			// ev.which兼容firefox， String.fromCharCode（将 Unicode 编码转为一个字符）
			return (/[\d]/.test(String.fromCharCode(ev.keyCode||ev.which)))
		}
	}
})

//在元素周围增加四个标识元素
Vue.directive('showIcon-4', {
	bind: function(el, binding) {
		el.style.position="relative"
		let style="position: absolute;width: 20px;height: 20px;",
		lt='left: 0;top:0;border-top:4px solid #43A0FF; border-left:4px solid #43A0FF;',
		lb='right:0;top:0;border-top:4px solid #43A0FF; border-right:4px solid #43A0FF;',
		rt='left: 0;bottom:0;border-bottom:4px solid #43A0FF; border-left:4px solid #43A0FF;',
		rb='right: 0;bottom:0;border-bottom:4px solid #43A0FF; border-right:4px solid #43A0FF;'
		var dom=`
		<div class="border-li border-li-lt" style="${style}${lt}"></div>
		<div class="border-li border-li-lb" style="${style}${lb}"></div>
		<div class="border-li border-li-rt" style="${style}${rt}"></div>
		<div class="border-li border-li-rb" style="${style}${rb}"></div>
		`
		let odiv = document.createElement('div');
		odiv.innerHTML=dom
		el.appendChild(odiv)
	}
})